/**
 * @Author: ls <ls-mac>
 * @Date:   2018-08-05 02:10:10
 * @Last modified by:   ls-mac
 * @Last modified time: 2019-10-29 21:51:05
 */

import React, { Component } from 'react';
import { Route, Redirect } from 'react-router-dom';
import Authorized from './Authorized';

// function AuthorizedRoute(props) {
// 	console.log(props);
//   const { component: Component, render, authority, children, redirectPath, ...rest } = props;
//
//   return (
//     <Authorized
//       authority={authority}
//       noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
//     >
//       <Route {...rest} render={props => (Component ? <Component {...props} /> : render(props))} />
//     </Authorized>
//   );
// }
//
// export default () => {
//   return <AuthorizedRoute />;
// };

export default class AuthorizedRoute extends Component {
  render() {
    const { component: Component, render, authority, children, redirectPath, ...rest } = this.props;
    return (
      <Authorized
        authority={authority}
        noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
      >
        <Route {...rest} render={props => (Component ? <Component {...props} /> : render(props))} />
      </Authorized>
    );
  }
}
